<?php

function return_json($status, $msg = null, $value = null){
    return json_encode(array('status'=>$status, 'msg'=>$msg, 'value'=>$value));
}
/**
 * GET请求
 * @param string $string
 * @return string
 */
function get($string =null){
    if($string === null){
        return $_GET;
    }
    return isset($_GET[$string]) ? $_GET[$string] : null;
}
function post($string =null){
    if($string === null){
        return $_POST;
    }
    return isset($_POST[$string]) ? $_POST[$string] : null;
}
function cookie($string =null){
    if($string === null){
        return $_COOKIE;
    }
    return isset($_COOKIE[$string]) ? $_COOKIE[$string] : null;
}
/**
 * 纯数字加密
 * @param string $string
 * @return NULL|string
 */
function encode($string){
    if(empty($string)){
        return null;
    }
    $arr = array('a','c','d','s','r','t','h','k','b','x');
    $str = '';
    for($i=0;$i<strlen($string);$i++){
        $str .= $arr[$string[$i]];
    }
    return $str;
}
/**
 * 纯数字解密
 * @param string $string
 * @return NULL|string
 */
function decode($string){
    if(empty($string)){
        return null;
    }
    $arr = array('a','c','d','s','r','t','h','k','b','x');
    $str = '';
    for($i=0;$i<strlen($string);$i++){
        $str .= array_search($string[$i], $arr);
    }
    return $str;
}
/**
 * 获取浏览器信息-name
 * @return string
 */
function getBrowser(){
    $agent=$_SERVER["HTTP_USER_AGENT"];
    if(strpos($agent,'MSIE')!==false || strpos($agent,'rv:11.0')){ //ie11判断
        return "ie";
    }
    if(strpos($agent,'Firefox')!==false){
        return "firefox";
    }
    if(strpos($agent,'Chrome')!==false){
        return "chrome";
    }
    if(strpos($agent,'Opera')!==false){
        return 'opera';
    }
    if((strpos($agent,'Chrome')==false) && strpos($agent,'Safari')!==false){
        return 'safari';
    }
    return 'unknown';
}




